Computation thinking
- Computation Thinking is the process of thinking how a problem can be solved.
- This invoves 2 basic steps:
- Formulate the problem as a computational program
- Try to construct an algorithm to solve the problem
Abstraction
- Abstraction involves filtering out (essentially, ignoring) the characteristics that we don't need in order to concentrate on
those that we do.
- Example: The operation of a mobile phone. You can make a call, send a message, or browse the internet without needing to know the
complex workings behind these operations.
Un-abstracted image with too much deatil
Abstracted Image
Abstraction Applied to High level programming languages
Abstraction is the most important feature of high level programming languages such as Python, C#, Java
and hundreds of other languages written for different purposes. To understand why, we need to look at the different
generations of programming languages:
- The first generation of language was machine code - programmers entered the binary Os and 1s
that the computer understands.
- The second generation was an improvement; mnemonic codes were used to represent instructions.
- The third generation of languages, starting with BASIC and FORTRAN in the 1960s, used statements
like X= A +5,
A famous example of abstraction is the city Königsberg and its bridge problem.
Computational Problems
At its most abstract level, a computational problem can be represented by a simple diagram:
- Input: is the information relevant to the problem, which could for example be passed as parameters to a
subroutine.
-
Output:is the solution to the problem.
Preconditions
In order to make sure a function never crashes, the function must pass a test-case for an empty input or a precondition
must be specified
Advantages of Precondtions:
- Specifying preconditions as part of the documentation of a subroutine ensures that the user knows what checks, if any,
must be carried out before calling the subroutine.
- Clear documentation of inputs, outputs and preconditions helps to make the subroutine reusable.
Nature and benefits of Caching
Caching is another aspect of thinking ahead, this time done automatically by the operating system
rather than the programmer. Caching is the temporary storage of program instructions or data that have
been used once and may be needed again shortly. The last few instructions of a program may be stored
in cache memory for quick retrieval.